Add gtk_widget_modify_{fg,bg,text,base,font}.
authorOwen Taylor <otaylor@redhat.com>
Tue, 22 Aug 2000 03:05:14 +0000 (03:05 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Tue, 22 Aug 2000 03:05:14 +0000 (03:05 +0000)
Mon Aug 21 22:39:18 2000  Owen Taylor  <otaylor@redhat.com>

        * gtk/gtkwidget.[ch]: Add gtk_widget_modify_{fg,bg,text,base,font}.

* gtk/testgtk.c (create_styles): Add a test for modifying
the style through gtk_widget_modify_*.

* gtk/gtkwidget.c (gtk_widget_get_modifier_style): Add
a function to get the current modifier style.

* gtk/gtkwidget.c (gtk_widget_modify_style): Make a copy
of the passed in GtkRcStyle instead of ref'ing it.

* gtk/gtkrc.[ch]: Add gtk_rc_style_copy().

13 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkrc.c
gtk/gtkrc.h
gtk/gtkwidget.c
gtk/gtkwidget.h
gtk/testgtk.c
tests/testgtk.c

index 726a4970fdf0473d8b13c4991842ba7983affbd5..c4d6fe9c5ba51951da4121b34c13d4fdd7560649 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Mon Aug 21 22:39:18 2000  Owen Taylor  <otaylor@redhat.com>
+
+        * gtk/gtkwidget.[ch]: Add gtk_widget_modify_{fg,bg,text,base,font}.
+       
+       * gtk/testgtk.c (create_styles): Add a test for modifying
+       the style through gtk_widget_modify_*.
+
+       * gtk/gtkwidget.c (gtk_widget_get_modifier_style): Add
+       a function to get the current modifier style.
+
+       * gtk/gtkwidget.c (gtk_widget_modify_style): Make a copy
+       of the passed in GtkRcStyle instead of ref'ing it.
+
+       * gtk/gtkrc.[ch]: Add gtk_rc_style_copy().
+
 2000-08-20  Tor Lillqvist  <tml@iki.fi>
 
        * gdk/gdkimage.h
index 726a4970fdf0473d8b13c4991842ba7983affbd5..c4d6fe9c5ba51951da4121b34c13d4fdd7560649 100644 (file)
@@ -1,3 +1,18 @@
+Mon Aug 21 22:39:18 2000  Owen Taylor  <otaylor@redhat.com>
+
+        * gtk/gtkwidget.[ch]: Add gtk_widget_modify_{fg,bg,text,base,font}.
+       
+       * gtk/testgtk.c (create_styles): Add a test for modifying
+       the style through gtk_widget_modify_*.
+
+       * gtk/gtkwidget.c (gtk_widget_get_modifier_style): Add
+       a function to get the current modifier style.
+
+       * gtk/gtkwidget.c (gtk_widget_modify_style): Make a copy
+       of the passed in GtkRcStyle instead of ref'ing it.
+
+       * gtk/gtkrc.[ch]: Add gtk_rc_style_copy().
+
 2000-08-20  Tor Lillqvist  <tml@iki.fi>
 
        * gdk/gdkimage.h
index 726a4970fdf0473d8b13c4991842ba7983affbd5..c4d6fe9c5ba51951da4121b34c13d4fdd7560649 100644 (file)
@@ -1,3 +1,18 @@
+Mon Aug 21 22:39:18 2000  Owen Taylor  <otaylor@redhat.com>
+
+        * gtk/gtkwidget.[ch]: Add gtk_widget_modify_{fg,bg,text,base,font}.
+       
+       * gtk/testgtk.c (create_styles): Add a test for modifying
+       the style through gtk_widget_modify_*.
+
+       * gtk/gtkwidget.c (gtk_widget_get_modifier_style): Add
+       a function to get the current modifier style.
+
+       * gtk/gtkwidget.c (gtk_widget_modify_style): Make a copy
+       of the passed in GtkRcStyle instead of ref'ing it.
+
+       * gtk/gtkrc.[ch]: Add gtk_rc_style_copy().
+
 2000-08-20  Tor Lillqvist  <tml@iki.fi>
 
        * gdk/gdkimage.h
index 726a4970fdf0473d8b13c4991842ba7983affbd5..c4d6fe9c5ba51951da4121b34c13d4fdd7560649 100644 (file)
@@ -1,3 +1,18 @@
+Mon Aug 21 22:39:18 2000  Owen Taylor  <otaylor@redhat.com>
+
+        * gtk/gtkwidget.[ch]: Add gtk_widget_modify_{fg,bg,text,base,font}.
+       
+       * gtk/testgtk.c (create_styles): Add a test for modifying
+       the style through gtk_widget_modify_*.
+
+       * gtk/gtkwidget.c (gtk_widget_get_modifier_style): Add
+       a function to get the current modifier style.
+
+       * gtk/gtkwidget.c (gtk_widget_modify_style): Make a copy
+       of the passed in GtkRcStyle instead of ref'ing it.
+
+       * gtk/gtkrc.[ch]: Add gtk_rc_style_copy().
+
 2000-08-20  Tor Lillqvist  <tml@iki.fi>
 
        * gdk/gdkimage.h
index 726a4970fdf0473d8b13c4991842ba7983affbd5..c4d6fe9c5ba51951da4121b34c13d4fdd7560649 100644 (file)
@@ -1,3 +1,18 @@
+Mon Aug 21 22:39:18 2000  Owen Taylor  <otaylor@redhat.com>
+
+        * gtk/gtkwidget.[ch]: Add gtk_widget_modify_{fg,bg,text,base,font}.
+       
+       * gtk/testgtk.c (create_styles): Add a test for modifying
+       the style through gtk_widget_modify_*.
+
+       * gtk/gtkwidget.c (gtk_widget_get_modifier_style): Add
+       a function to get the current modifier style.
+
+       * gtk/gtkwidget.c (gtk_widget_modify_style): Make a copy
+       of the passed in GtkRcStyle instead of ref'ing it.
+
+       * gtk/gtkrc.[ch]: Add gtk_rc_style_copy().
+
 2000-08-20  Tor Lillqvist  <tml@iki.fi>
 
        * gdk/gdkimage.h
index 726a4970fdf0473d8b13c4991842ba7983affbd5..c4d6fe9c5ba51951da4121b34c13d4fdd7560649 100644 (file)
@@ -1,3 +1,18 @@
+Mon Aug 21 22:39:18 2000  Owen Taylor  <otaylor@redhat.com>
+
+        * gtk/gtkwidget.[ch]: Add gtk_widget_modify_{fg,bg,text,base,font}.
+       
+       * gtk/testgtk.c (create_styles): Add a test for modifying
+       the style through gtk_widget_modify_*.
+
+       * gtk/gtkwidget.c (gtk_widget_get_modifier_style): Add
+       a function to get the current modifier style.
+
+       * gtk/gtkwidget.c (gtk_widget_modify_style): Make a copy
+       of the passed in GtkRcStyle instead of ref'ing it.
+
+       * gtk/gtkrc.[ch]: Add gtk_rc_style_copy().
+
 2000-08-20  Tor Lillqvist  <tml@iki.fi>
 
        * gdk/gdkimage.h
index 726a4970fdf0473d8b13c4991842ba7983affbd5..c4d6fe9c5ba51951da4121b34c13d4fdd7560649 100644 (file)
@@ -1,3 +1,18 @@
+Mon Aug 21 22:39:18 2000  Owen Taylor  <otaylor@redhat.com>
+
+        * gtk/gtkwidget.[ch]: Add gtk_widget_modify_{fg,bg,text,base,font}.
+       
+       * gtk/testgtk.c (create_styles): Add a test for modifying
+       the style through gtk_widget_modify_*.
+
+       * gtk/gtkwidget.c (gtk_widget_get_modifier_style): Add
+       a function to get the current modifier style.
+
+       * gtk/gtkwidget.c (gtk_widget_modify_style): Make a copy
+       of the passed in GtkRcStyle instead of ref'ing it.
+
+       * gtk/gtkrc.[ch]: Add gtk_rc_style_copy().
+
 2000-08-20  Tor Lillqvist  <tml@iki.fi>
 
        * gdk/gdkimage.h
index 6b651a75ca35c95ed98cce2daffb94d8b8d419d7..c31fc5062d273e32e9f1420d49aad7c3e85286c5 100644 (file)
@@ -871,6 +871,29 @@ gtk_rc_style_new (void)
   return style;
 }
 
+/**
+ * gtk_rc_style_copy:
+ * @orig: the style to copy
+ * 
+ * Make a copy of the specified #GtkRcStyle. This function
+ * will correctly copy an rc style that is a member of a class
+ * derived from #GtkRcStyle.
+ * 
+ * Return value: the resulting #GtkRcStyle
+ **/
+GtkRcStyle *
+gtk_rc_style_copy (GtkRcStyle *orig)
+{
+  GtkRcStyle *style;
+
+  g_return_if_fail (GTK_IS_RC_STYLE (orig));
+  
+  style = GTK_RC_STYLE_GET_CLASS (orig)->clone (orig);
+  GTK_RC_STYLE_GET_CLASS (style)->merge (style, orig);
+
+  return style;
+}
+
 void      
 gtk_rc_style_ref (GtkRcStyle  *rc_style)
 {
index ebe1bf2c625a5ab588a38eca4208feb6619b475c..31ed6069709516f6223b5baeb7fafd970c5ce0d5 100644 (file)
@@ -121,6 +121,7 @@ void          gtk_rc_add_class_style        (GtkRcStyle  *rc_style,
 
 GType       gtk_rc_style_get_type   (void);
 GtkRcStyle* gtk_rc_style_new        (void);
+GtkRcStyle *gtk_rc_style_copy       (GtkRcStyle *orig);
 void        gtk_rc_style_ref        (GtkRcStyle *rc_style);
 void        gtk_rc_style_unref      (GtkRcStyle *rc_style);
 
index 4fb3feb01fbd6a097c699c856d198e03ef883408..440cbbaa7c61b4cd86e17f1b07397936839c8756 100644 (file)
@@ -3035,27 +3035,239 @@ gtk_widget_get_style (GtkWidget *widget)
   return widget->style;
 }
 
+/**
+ * gtk_widget_modify_style:
+ * @widget: a #GtkWidget
+ * @style: the #GtkRcStyle holding the style modifications
+ * 
+ * Modify style values on the widget. Modifications made using this
+ * technique take precendence over style values set via an RC file,
+ * however, they will be overriden if a style is explicitely set on
+ * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
+ * is designed so each field can either be set or unset, so it is
+ * possible, using this function, to modify some style values and
+ * leave the others unchanged.
+ *
+ * Note that modifications made with this function are not cumulative
+ * with previous calls to gtk_widget_modify_style() or with such
+ * functions as gtk_widget_modify_fg(). If you wish to retain
+ * previous values, you must first call gtk_widget_get_modifier_style(),
+ * make your modifications to the returned style, then call
+ * gtk_widget_modify_style() with that style. On the other hand,
+ * if you first call gtk_widget_modify_style(), subsequent calls
+ * to such functions gtk_widget_modify_fg() will be have a cumulative
+ * effect with the inital modifications.
+ **/
 void       
 gtk_widget_modify_style (GtkWidget      *widget,
                         GtkRcStyle     *style)
 {
   GtkRcStyle *old_style;
+
+  g_return_if_fail (GTK_IS_RC_STYLE (style));
   
   if (!rc_style_key_id)
     rc_style_key_id = g_quark_from_static_string (rc_style_key);
 
-  old_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), rc_style_key_id);
+  old_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
+                                        rc_style_key_id);
 
   if (style != old_style)
+    gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
+                                   rc_style_key_id,
+                                   gtk_rc_style_copy (style),
+                                   (GtkDestroyNotify)gtk_rc_style_unref);
+
+  if (GTK_WIDGET_RC_STYLE (widget))
+    gtk_widget_set_rc_style (widget);
+}
+
+/**
+ * gtk_widget_get_modifier_style:
+ * @widget: a #GtkWidget
+ * 
+ * Return the current modifier style for the widget. (As set by
+ * gtk_widget_modify_style().) If no style has previously set, a new
+ * #GtkRcStyle will be created with all values unset, and set as the
+ * modifier style for the widget. If you make changes to this rc
+ * style, you must call gtk_widget_modify_style(), passing in the
+ * returned rc style, to make sure that your changes take effect.
+ * 
+ * Return value: the modifier style for the widget. This rc style is
+ *   owned by the widget. If you want to keep a pointer to value this
+ *   around, you must add a refcount using gtk_rc_style_ref().
+ **/
+GtkRcStyle *
+gtk_widget_get_modifier_style (GtkWidget      *widget)
+{
+  GtkRcStyle *rc_style;
+  
+  if (!rc_style_key_id)
+    rc_style_key_id = g_quark_from_static_string (rc_style_key);
+  
+  rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
+                                       rc_style_key_id);
+
+  if (!rc_style)
     {
-      gtk_rc_style_ref (style);
-      
+      rc_style = gtk_rc_style_new();
       gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
                                      rc_style_key_id,
-                                     style,
+                                     rc_style,
                                      (GtkDestroyNotify)gtk_rc_style_unref);
     }
 
+  return rc_style;
+}
+
+static void
+gtk_widget_modify_color_component (GtkWidget     *widget,
+                                  GtkRcFlags     component,
+                                  GtkStateType   state,
+                                  GdkColor      *color)
+{
+  GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);  
+
+  switch (component)
+    {
+    case GTK_RC_FG:
+      rc_style->fg[state] = *color;
+      break;
+    case GTK_RC_BG:
+      rc_style->bg[state] = *color;
+      break;
+    case GTK_RC_TEXT:
+      rc_style->text[state] = *color;
+       break;
+    case GTK_RC_BASE:
+      rc_style->base[state] = *color;
+      break;
+    default:
+      g_assert_not_reached();
+    }
+
+  rc_style->color_flags[state] |= component;
+
+  if (GTK_WIDGET_RC_STYLE (widget))
+    gtk_widget_set_rc_style (widget);
+}
+
+/**
+ * gtk_widget_modify_fg:
+ * @widget: a #GtkWidget
+ * @state: the state for which to set the foreground color.
+ * @color: the color to assign (does not need to be allocated)
+ * 
+ * Set the foreground color for a widget in a particular state.  All
+ * other style values are left untouched. See also
+ * gtk_widget_modify_style().
+ **/
+void
+gtk_widget_modify_fg (GtkWidget   *widget,
+                     GtkStateType state,
+                     GdkColor    *color)
+{
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
+  g_return_if_fail (color != NULL);
+
+  gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
+}
+
+/**
+ * gtk_widget_modify_bg:
+ * @widget: a #GtkWidget
+ * @state: the state for which to set the foreground color.
+ * @color: the color to assign (does not need to be allocated)
+ * 
+ * Set the background color for a widget in a particular state.  All
+ * other style values are left untouched. See also
+ * gtk_widget_modify_style().
+ **/
+void
+gtk_widget_modify_bg (GtkWidget   *widget,
+                     GtkStateType state,
+                     GdkColor    *color)
+{
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
+  g_return_if_fail (color != NULL);
+
+  gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
+}
+
+/**
+ * gtk_widget_modify_base:
+ * @widget: a #GtkWidget
+ * @state: the state for which to set the foreground color.
+ * @color: the color to assign (does not need to be allocated)
+ * 
+ * Set the text color for a widget in a particular state.  All other
+ * style values are left untouched. The text color is the foreground
+ * color used along with the base color (see gtk_widget_modify_base)
+ * for widgets such as #GtkEntry and #GtkTextView. See also
+ * gtk_widget_modify_style().
+ **/
+void
+gtk_widget_modify_text (GtkWidget   *widget,
+                       GtkStateType state,
+                       GdkColor    *color)
+{
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
+  g_return_if_fail (color != NULL);
+
+  gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
+}
+
+/**
+ * gtk_widget_modify_base:
+ * @widget: a #GtkWidget
+ * @state: the state for which to set the foreground color.
+ * @color: the color to assign (does not need to be allocated)
+ * 
+ * Set the text color for a widget in a particular state.
+ * All other style values are left untouched. The base color
+ * is the background color used along with the text color
+ * (see gtk_widget_modify_text) for widgets such as #GtkEntry
+ * and #GtkTextView. See also gtk_widget_modify_style().
+ **/
+void
+gtk_widget_modify_base (GtkWidget  *widget,
+                       GtkStateType state,
+                       GdkColor    *color)
+{
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
+  g_return_if_fail (color != NULL);
+
+  gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
+}
+
+/**
+ * gtk_widget_modify_font:
+ * @widget: a #GtkWidget
+ * @font: the font description to use
+ * 
+ * Set the font to use for a widget.  All other style values are left
+ * untouched. See also gtk_widget_modify_style().
+ **/
+void
+gtk_widget_modify_font (GtkWidget            *widget,
+                       PangoFontDescription *font_desc)
+{
+  GtkRcStyle *rc_style;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (font_desc != NULL);
+
+  rc_style = gtk_widget_get_modifier_style (widget);  
+
+  if (rc_style->font_desc)
+    pango_font_description_free (rc_style->font_desc);
+  
+  rc_style->font_desc = pango_font_description_copy (font_desc);
+  
   if (GTK_WIDGET_RC_STYLE (widget))
     gtk_widget_set_rc_style (widget);
 }
index 0d754ef02202f7e4718771a2175ec55422661d40..2b10f071a6f5668bfce07a4243101c9e0a903d9b 100644 (file)
@@ -572,8 +572,23 @@ void          gtk_widget_ensure_style      (GtkWidget      *widget);
 GtkStyle*  gtk_widget_get_style                (GtkWidget      *widget);
 void      gtk_widget_restore_default_style (GtkWidget  *widget);
 
-void       gtk_widget_modify_style      (GtkWidget      *widget,
-                                        GtkRcStyle     *style);
+void        gtk_widget_modify_style       (GtkWidget            *widget,
+                                          GtkRcStyle           *style);
+GtkRcStyle *gtk_widget_get_modifier_style (GtkWidget            *widget);
+void        gtk_widget_modify_fg          (GtkWidget            *widget,
+                                          GtkStateType          state,
+                                          GdkColor             *color);
+void        gtk_widget_modify_bg          (GtkWidget            *widget,
+                                          GtkStateType          state,
+                                          GdkColor             *color);
+void        gtk_widget_modify_text        (GtkWidget            *widget,
+                                          GtkStateType          state,
+                                          GdkColor             *color);
+void        gtk_widget_modify_base        (GtkWidget            *widget,
+                                          GtkStateType          state,
+                                          GdkColor             *color);
+void        gtk_widget_modify_font        (GtkWidget            *widget,
+                                          PangoFontDescription *font_desc);
 
 PangoContext *gtk_widget_create_pango_context (GtkWidget   *widget);
 PangoContext *gtk_widget_get_pango_context    (GtkWidget   *widget);
index 924221fbc9c0deec6ca20019d1bb262a6f57d4e6..0f01ddf7149567b356c89477fc3ca9e42e27800f 100644 (file)
@@ -8472,6 +8472,125 @@ void create_layout (void)
     gtk_widget_destroy (window);
 }
 
+void
+create_styles (void)
+{
+  static GtkWidget *window = NULL;
+  GtkWidget *label;
+  GtkWidget *button;
+  GtkWidget *entry;
+  GtkWidget *vbox;
+  static GdkColor red =    { 0, 0xffff, 0,      0      };
+  static GdkColor green =  { 0, 0,      0xffff, 0      };
+  static GdkColor blue =   { 0, 0,      0,      0xffff };
+  static GdkColor yellow = { 0, 0xffff, 0xffff, 0      };
+  static GdkColor cyan =   { 0, 0     , 0xffff, 0xffff };
+  PangoFontDescription *font_desc;
+
+  GtkRcStyle *rc_style;
+
+  if (!window)
+    {
+      window = gtk_dialog_new ();
+      gtk_signal_connect (GTK_OBJECT (window), "destroy",
+                         GTK_SIGNAL_FUNC(gtk_widget_destroyed),
+                         &window);
+
+      
+      button = gtk_button_new_with_label ("Close");
+      gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
+                                GTK_SIGNAL_FUNC(gtk_widget_destroy),
+                                GTK_OBJECT (window));
+      GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
+                         button, TRUE, TRUE, 0);
+      gtk_widget_show (button);
+
+      vbox = gtk_vbox_new (FALSE, 5);
+      gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
+      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, FALSE, FALSE, 0);
+      
+      label = gtk_label_new ("Font:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      font_desc = pango_font_description_from_string ("Helvetica,Sans Oblique 18");
+
+      button = gtk_button_new_with_label ("Some Text");
+      gtk_widget_modify_font (GTK_BIN (button)->child, font_desc);
+      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+      label = gtk_label_new ("Foreground:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      button = gtk_button_new_with_label ("Some Text");
+      gtk_widget_modify_fg (GTK_BIN (button)->child, GTK_STATE_NORMAL, &red);
+      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+      label = gtk_label_new ("Background:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      button = gtk_button_new_with_label ("Some Text");
+      gtk_widget_modify_bg (button, GTK_STATE_NORMAL, &green);
+      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+      label = gtk_label_new ("Text:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      entry = gtk_entry_new ();
+      gtk_entry_set_text (GTK_ENTRY (entry), "Some Text");
+      gtk_widget_modify_text (entry, GTK_STATE_NORMAL, &blue);
+      gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+
+      label = gtk_label_new ("Base:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      entry = gtk_entry_new ();
+      gtk_entry_set_text (GTK_ENTRY (entry), "Some Text");
+      gtk_widget_modify_base (entry, GTK_STATE_NORMAL, &yellow);
+      gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+
+      label = gtk_label_new ("Multiple:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      button = gtk_button_new_with_label ("Some Text");
+
+      rc_style = gtk_rc_style_new ();
+
+      rc_style->font_desc = font_desc;
+      rc_style->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG | GTK_RC_BG;
+      rc_style->color_flags[GTK_STATE_PRELIGHT] = GTK_RC_FG | GTK_RC_BG;
+      rc_style->color_flags[GTK_STATE_ACTIVE] = GTK_RC_FG | GTK_RC_BG;
+      rc_style->fg[GTK_STATE_NORMAL] = yellow;
+      rc_style->bg[GTK_STATE_NORMAL] = blue;
+      rc_style->fg[GTK_STATE_PRELIGHT] = blue;
+      rc_style->bg[GTK_STATE_PRELIGHT] = yellow;
+      rc_style->fg[GTK_STATE_ACTIVE] = red;
+      rc_style->bg[GTK_STATE_ACTIVE] = cyan;
+      rc_style->xthickness = 5;
+      rc_style->ythickness = 5;
+
+      gtk_widget_modify_style (button, rc_style);
+      gtk_widget_modify_style (GTK_BIN (button)->child, rc_style);
+
+      g_object_unref (G_OBJECT (rc_style));
+      
+      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+      pango_font_description_free (font_desc);
+    }
+  
+  if (!GTK_WIDGET_VISIBLE (window))
+    gtk_widget_show_all (window);
+  else
+    gtk_widget_destroy (window);
+}
+
 /*
  * Main Window and Exit
  */
@@ -8529,6 +8648,7 @@ create_main_window (void)
       { "shapes", create_shapes },
       { "spinbutton", create_spins },
       { "statusbar", create_statusbar },
+      { "styles", create_styles },
       { "test idle", create_idle_test },
       { "test mainloop", create_mainloop },
       { "test scrolling", create_scroll_test },
index 924221fbc9c0deec6ca20019d1bb262a6f57d4e6..0f01ddf7149567b356c89477fc3ca9e42e27800f 100644 (file)
@@ -8472,6 +8472,125 @@ void create_layout (void)
     gtk_widget_destroy (window);
 }
 
+void
+create_styles (void)
+{
+  static GtkWidget *window = NULL;
+  GtkWidget *label;
+  GtkWidget *button;
+  GtkWidget *entry;
+  GtkWidget *vbox;
+  static GdkColor red =    { 0, 0xffff, 0,      0      };
+  static GdkColor green =  { 0, 0,      0xffff, 0      };
+  static GdkColor blue =   { 0, 0,      0,      0xffff };
+  static GdkColor yellow = { 0, 0xffff, 0xffff, 0      };
+  static GdkColor cyan =   { 0, 0     , 0xffff, 0xffff };
+  PangoFontDescription *font_desc;
+
+  GtkRcStyle *rc_style;
+
+  if (!window)
+    {
+      window = gtk_dialog_new ();
+      gtk_signal_connect (GTK_OBJECT (window), "destroy",
+                         GTK_SIGNAL_FUNC(gtk_widget_destroyed),
+                         &window);
+
+      
+      button = gtk_button_new_with_label ("Close");
+      gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
+                                GTK_SIGNAL_FUNC(gtk_widget_destroy),
+                                GTK_OBJECT (window));
+      GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
+      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area), 
+                         button, TRUE, TRUE, 0);
+      gtk_widget_show (button);
+
+      vbox = gtk_vbox_new (FALSE, 5);
+      gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
+      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, FALSE, FALSE, 0);
+      
+      label = gtk_label_new ("Font:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      font_desc = pango_font_description_from_string ("Helvetica,Sans Oblique 18");
+
+      button = gtk_button_new_with_label ("Some Text");
+      gtk_widget_modify_font (GTK_BIN (button)->child, font_desc);
+      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+      label = gtk_label_new ("Foreground:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      button = gtk_button_new_with_label ("Some Text");
+      gtk_widget_modify_fg (GTK_BIN (button)->child, GTK_STATE_NORMAL, &red);
+      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+      label = gtk_label_new ("Background:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      button = gtk_button_new_with_label ("Some Text");
+      gtk_widget_modify_bg (button, GTK_STATE_NORMAL, &green);
+      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+      label = gtk_label_new ("Text:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      entry = gtk_entry_new ();
+      gtk_entry_set_text (GTK_ENTRY (entry), "Some Text");
+      gtk_widget_modify_text (entry, GTK_STATE_NORMAL, &blue);
+      gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+
+      label = gtk_label_new ("Base:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      entry = gtk_entry_new ();
+      gtk_entry_set_text (GTK_ENTRY (entry), "Some Text");
+      gtk_widget_modify_base (entry, GTK_STATE_NORMAL, &yellow);
+      gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+
+      label = gtk_label_new ("Multiple:");
+      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+      button = gtk_button_new_with_label ("Some Text");
+
+      rc_style = gtk_rc_style_new ();
+
+      rc_style->font_desc = font_desc;
+      rc_style->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG | GTK_RC_BG;
+      rc_style->color_flags[GTK_STATE_PRELIGHT] = GTK_RC_FG | GTK_RC_BG;
+      rc_style->color_flags[GTK_STATE_ACTIVE] = GTK_RC_FG | GTK_RC_BG;
+      rc_style->fg[GTK_STATE_NORMAL] = yellow;
+      rc_style->bg[GTK_STATE_NORMAL] = blue;
+      rc_style->fg[GTK_STATE_PRELIGHT] = blue;
+      rc_style->bg[GTK_STATE_PRELIGHT] = yellow;
+      rc_style->fg[GTK_STATE_ACTIVE] = red;
+      rc_style->bg[GTK_STATE_ACTIVE] = cyan;
+      rc_style->xthickness = 5;
+      rc_style->ythickness = 5;
+
+      gtk_widget_modify_style (button, rc_style);
+      gtk_widget_modify_style (GTK_BIN (button)->child, rc_style);
+
+      g_object_unref (G_OBJECT (rc_style));
+      
+      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+      pango_font_description_free (font_desc);
+    }
+  
+  if (!GTK_WIDGET_VISIBLE (window))
+    gtk_widget_show_all (window);
+  else
+    gtk_widget_destroy (window);
+}
+
 /*
  * Main Window and Exit
  */
@@ -8529,6 +8648,7 @@ create_main_window (void)
       { "shapes", create_shapes },
       { "spinbutton", create_spins },
       { "statusbar", create_statusbar },
+      { "styles", create_styles },
       { "test idle", create_idle_test },
       { "test mainloop", create_mainloop },
       { "test scrolling", create_scroll_test },